<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
	<title>task</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<style type="text/css">
.datagrid-mask {
	background: #ccc;
}

.datagrid-mask-msg {
	border-color: #95B8E7;
}

.datagrid-mask-msg {
	background: #ffffff url('<c:url value="/resources/images/loading.gif" />') no-repeat scroll 5px center;
}

.datagrid-mask {
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	opacity: 0.3;
	filter: alpha(opacity = 30);
	display: none;
}

.datagrid-mask-msg {
	position: absolute;
	top: 50%;
	margin-top: -20px;
	padding: 12px 5px 10px 30px;
	width: auto;
	height: 16px;
	border-width: 2px;
	border-style: solid;
	display: none;
}

.list_table {
	border: 1px solid #CCCCCC;
	border-collapse: collapse;
	color: #333333;
	margin: 0 0 0;
	width: 100%;
}

.list_table tbody td {
	border-top: 1px solid #CCCCCC;
	text-align: left;
}

.list_table th {
	line-height: 1.2em;
	vertical-align: top;
}

.list_table td {
	line-height: 2em;
	font-size: 12px;
	vertical-align: central;
	text-align: left;
}

.list_table td input {
	width: 90%;
}

.list_table tbody tr:hover th,.list_table tbody tr:hover td {
	background: #EEF0F2;
}

.list_table thead tr {
	background: none repeat scroll 0 0 #09f;
	color: #fff;
	font-weight: bold;
	border-bottom: 1px solid #CCCCCC;
	border-right: 1px solid #CCCCCC;
}
</style>
</head>


<body class="bgray">

<div class="content">
	<div class="title fix">
		<h3 class="b f14 fl">定时任务管理</h3>
		<%-- <div class="f14 fl " style="margin-top: 30px; margin-left:30px; "><a href='<c:url value="/remind/sms/manage/${dealerNum}" />' >短信余额<label class="msg-label orange b" id="smsQuantity">${smsQuantity}</label></a></div> --%>
		<div class="btns fr">
			<%--<button class="green" onclick="add()">新增</button>--%>
			<%--<button class="orange">返回</button>--%>
		</div>
	</div>
	<div class="main">
		<div class="inquiry">
			<form id="searchForm">
				<input type="hidden" name="currentPage" value="1">
				<input type="hidden" name="toolStyle" value="pms">
				<input type="hidden" name="limit" value="10">
				<input type="hidden" name="method" value="toPage">

				<%--<div class="group"><label>活动名称：</label><input type="text" name="name" value=" " /></div>--%>
				<%--<div class="group"><label>活动时间：</label><input type="text" name="name" value=" " /> - <input type="text" name="name" value=" " /></div>--%>
				<%--<div class="group"><label>活动状态：</label><input type="text" name="name" value=" " /></div>--%>
				<%--<div class="btns"><button type="button" class="bottleGreen vm" onclick="toPage(1)">查看</button></div>--%>
			</form>
		</div>
	<div class="table">
		<table width="100%">
			<thead>
				<tr>
					<th style="width: 40px">id</th>
					<th>name</th>
					<th>group</th>
					<th>状态&nbsp;&nbsp;</th>
					<th>下次执行时间</th>
					<th>最后执行时间</th>
					<th>最后执行结果</th>
					<th>cron表达式</th>
					<th>描述</th>
					<th>同步否</th>
					<%--<th>类路径</th>--%>
					<th>spring id</th>
					<th>method</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody class="detailTr">
				<c:forEach var="job" items="${taskList}">
					<tr>
						<td>${job.jobId }</td>
						<td>${job.jobName }</td>
						<td>${job.jobGroup }</td>
						<td>${job.jobStatus eq '1' ? '开启':'停止' }</td>
						<td><fmt:formatDate value="${job.nextFireTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
						<td>
							<fmt:formatDate value="${job.lastRunBeginTime }" pattern="yyyy-MM-dd HH:mm:ss" />
							- <fmt:formatDate value="${job.lastRunEndTime }" pattern="HH:mm:ss" />
						</td>
						<td>${job.lastRunSuccessFlag }(${job.lastRunDescp })</td>
						<td>${job.cronExpression }</td>
						<td>${job.description }</td>
						<td>${job.isConcurrent }</td>
						<%--<td>${job.beanClass }</td>--%>
						<td>${job.springId }</td>
						<td>${job.methodName }</td>
						<td class="operate_td">
							<a href="javascript:;" onclick="changeJobStatus('${job.jobId}','${job.jobStatus eq '1' ? 'stop':'start' }')">${job.jobStatus ne '1' ? '开启':'停止' }</a>
							<a href="javascript:;" onclick="runJob('${job.jobId}')">立即执行</a>
						    <a href="javascript:;" onclick="updateCron('${job.jobId}')">更新cron</a>
						</td>
					</tr>
				</c:forEach>

			</tbody>
		</table>
		</div>

	</div>

		<div style="font-size: 12px; line-height: 30px; margin-left: 15px;">
			<form id="addForm" method="post">
			<input type="hidden" name="jobStatus" value="0" />

				任务名称:<input type="text" name="jobName" id="jobName"  />

				<br/>任务分组:<input type="text" name="jobGroup" id="jobGroup" />

				<br/>执行时间(cron表达式):<input type="text" name="cronExpression" id="cronExpression" />
				<br/>说 明:	<input type="text" name="description" id="description"/>
				<br/>运行同步规则<select name="isConcurrent" id="isConcurrent">
						<option value="1">同步</option>
						<option value="0">不同步</option>
					</select>
				<br/>SpringId:<input type="text" name="springId" id="springId"/>
				<input type="hidden" name="beanClass" id="beanClass"/>
				<%--<br/>Class Name:<input type="text" name="beanClass" id="beanClass"/>--%>
				<br/>Method name:<input type="text" name="methodName" id="methodName"/>
				<br/><input type="button" onclick="add()" value="保存" />
			</form>
		</div>
	</div>
	<script>
		function validateAdd() {

			if ($.trim($('#jobName').val()) == '') {
				alert('name不能为空！');
				$('#jobName').focus();
				return false;
			}
			if ($.trim($('#jobGroup').val()) == '') {
				alert('group不能为空！');
				$('#jobGroup').focus();
				return false;
			}
			if ($.trim($('#cronExpression').val()) == '') {
				alert('cron表达式不能为空！');
				$('#cronExpression').focus();
				return false;
			}
			if ($.trim($('#beanClass').val()) == '' && $.trim($('#springId').val()) == '') {
				$('#beanClass').focus();
				alert('类路径和spring id至少填写一个');
				return false;
			}
			if ($.trim($('#methodName').val()) == '') {
				$('#methodName').focus();
				alert('方法名不能为空！');
				return false;
			}
			return true;
		}
		function add() {
			if (validateAdd()) {
				showWaitMsg();
				$.ajax({
					type : "POST",
					async : false,
					dataType : "JSON",
					cache : false,
					url : '<c:url value="/task/add" />',
					data : $("#addForm").serialize(),
					success : function(data) {
						hideWaitMsg();
						if (data.flag) {

							location.reload();
						} else {
							alert(data.msg);
						}

					}//end-callback
				});//end-ajax
			}
		}
		function changeJobStatus(jobId, cmd) {
			showWaitMsg();
			$.ajax({
				type : "POST",
				async : false,
				dataType : "JSON",
				cache : false,
				url : '<c:url value="/task/changeJobStatus" />',
				data : {
					jobId : jobId,
					cmd : cmd
				},
				success : function(data) {
					hideWaitMsg();
					if (data.flag) {

						location.reload();
					} else {
						alert(data.msg);
					}

				}//end-callback
			});//end-ajax
		}
		function updateCron(jobId) {
			var cron = prompt("输入cron表达式！", "");
			if (cron) {
				showWaitMsg();

				$.ajax({
					type : "POST",
					async : false,
					dataType : "JSON",
					cache : false,
					url : '<c:url value="/task/updateCron" />',
					data : {
						jobId : jobId,
						cron : cron
					},
					success : function(data) {
						hideWaitMsg();
						if (data.flag) {

							location.reload();
						} else {
							alert(data.msg);
						}

					}//end-callback
				});//end-ajax
			}

		}
		function runJob(jobId) {

				showWaitMsg();

				$.ajax({
					type : "POST",
					async : true,
					dataType : "JSON",
					cache : false,
					url : '<c:url value="/task/run/" />' + jobId ,
					success : function(data) {
						hideWaitMsg();
						if (data.flag) {
							alert("执行命令发送成功！");
							//location.reload();
						} else {
							alert(data.msg);
						}

					}//end-callback
				});//end-ajax


		}
		function showWaitMsg(msg) {
			if (msg) {

			} else {
				msg = '正在处理，请稍候...';
			}
			var panelContainer = $("body");
			$("<div id='msg-background' class='datagrid-mask' style=\"display:block;z-index:10006;\"></div>").appendTo(panelContainer);
			var msgDiv = $("<div id='msg-board' class='datagrid-mask-msg' style=\"display:block;z-index:10007;left:50%\"></div>").html(msg).appendTo(
					panelContainer);
			msgDiv.css("marginLeft", -msgDiv.outerWidth() / 2);
		}
		function hideWaitMsg() {
			$('.datagrid-mask').remove();
			$('.datagrid-mask-msg').remove();
		}
	</script>

</body>
</html>




